package com.exchange;

import org.json.JSONArray;

import android.R.bool;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;

public class CardManger {
	
	interface Listener{
		public void find( String info );
		public void searchFinish();
	}
	
	final static String TAG = "##";

	static CardManger instance = new CardManger();

	Listener listener;
	
	public static CardManger getInstance() {
		return instance;
	}

	public void setListener( Listener listener ) {
		this.listener = listener;
	}
	
	public static String gererateName(String name, String phone) {
		JSONArray array = new JSONArray();
		array.put(TAG);
		array.put(name);
		array.put(phone);
		return array.toString();
	} 
	
	public void parseName(String value) {  
		try {
			JSONArray array = new JSONArray(value);
			if (array.get(0).equals(TAG)) { 
				listener.find("Find:" + array.get(1)+ "  " + array.get(2) ); 
				MyApplication.vibrate(1000);
			} 
		} catch (Throwable e) {  
		} 
		System.out.println("array:" + value);
	}
	
	public void searchFinish() {
		if( listener != null ){
			listener.searchFinish();
		}		
	}
}
